package com.jky.stmall.front.mapper;

import com.jky.stmall.front.entity.OrderDetail;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderDetailMapper {

    //添加 一个订单下至少应该有一条详情，也可能同时包含多条订单详情
    @Insert({"<script>",
            "insert into order_detail",
            "(count,price,goods_id,order_id)",
            "value",
            "<foreach collection='orderDetails' item='orderDetail' separator=','>",
            "(#{orderDetail.count},#{orderDetail.price},#{orderDetail.goodsId},#{orderDetail.orderId})",
            "</foreach>",
            "</script>",
    })
    int insertBatch(@Param("orderDetails") List<OrderDetail> orderDetails);

    /*使用Param注解
    * 1.参数不止一个
    * 2.只有一个参数 但是这个参数不是简单类型（基本数据类型和包装类 String），也不是实体类
    *  如果是数组 默认参数为：array arg0
    * 如果或是集合默认参数名为 arg0
    * */
    @Delete("delete from order_detail where order_id=#{orderId}")
    //删除，根据订单的Id删除
    int deleteByOrderId(String orderId);

    //修改 不能修改


    //根据订单的id  查询订单的详情列表

    @Select("select * from order_detail where order_id=#{orderId}")
    @Results({
            @Result(column = "goods_id",property = "goodsId"),
            @Result(column = "goods_id",property = "goods",
            one = @One(select = "com.jky.stmall.front.mapper.GoodsMapper.selectById"))
    })
    List<OrderDetail> selectByOrderId(String orderId);
}
